package ext.tianma.masschange.datautility;

import org.apache.log4j.Logger;

import com.ptc.carambola.rendering.HTMLComponent;
import com.ptc.core.components.descriptor.ComponentDescriptor;
import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.dataUtilities.AttributeDataUtilityHelper;
import com.ptc.core.components.factory.dataUtilities.DefaultDataUtility;
import com.ptc.core.components.factory.dataUtilities.NumberDataUtility;
import com.ptc.core.components.rendering.guicomponents.AttributeGuiComponent;
import com.ptc.core.components.rendering.guicomponents.GUIComponentArray;
import com.ptc.core.components.rendering.guicomponents.TextBox;
import com.ptc.core.meta.common.TypeIdentifier;
import com.ptc.core.ui.resources.ComponentMode;

import wt.httpgw.URLFactory;
import wt.log4j.LogR;
import wt.util.WTException;

public class SelectCheckHref extends NumberDataUtility {
	private static final Logger log = LogR.getLogger(SelectCheckHref.class.getName());
	//private Locale locale;
	@Override
	public Object getDataValue(String s, Object obj, ModelContext modelcontext) throws WTException {
		System.out.println("===============start into ==================");
		Object object=new DefaultDataUtility().getDataValue(s, obj, modelcontext);
		AttributeGuiComponent component=(AttributeGuiComponent)object;
		
		//log.info("in__________-------------------------");
		log.debug("in__________-------------------------");
		//log.info("s__________-------------------------"+s);
		log.debug("s__________-------------------------"+s);
		//log.info("modelcontext__________-------------------------"+modelcontext);
		log.debug("modelcontext__________-------------------------"+modelcontext);
		Object localObject="";
		String baseUrl = "http://siasdev.patac.com/Windchill/";
		URLFactory urlfactory;
		try {
			urlfactory = new URLFactory();
			baseUrl = urlfactory.getBaseHREF();
			
		} catch (Exception e) {
			//e.printStackTrace();
			log.error(e.getMessage(), e);
		}
		
		GUIComponentArray componentArray = new GUIComponentArray();
		//locale = modelcontext.getNmCommandBean() == null ? Locale.getDefault() : modelcontext.getNmCommandBean().getLocale();
		TypeIdentifier typeidentifier = modelcontext.getTypeIdentifier();
		//log.info("getTypename-------------------------"+typeidentifier.getTypename());
		modelcontext.getNmCommandBean().getComboBox();
		int i = calculateMaxCharacterEntryLimit(modelcontext);
		ComponentDescriptor componentdescriptor = modelcontext
				.getDescriptor();
		String s1 = componentdescriptor.getModelAttributeString();
		if (s1 == null || s1.length() == 0)
			s1 = s;
		String namevalue =AttributeDataUtilityHelper.getValue(modelcontext, s);
		
		//System.out.println("------------------------------------s"+s);
		log.debug("------------------------------------s"+s);
		TextBox box = new TextBox();
        box.setInputType("hidden");
        box.setId(s1);
        box.setRequired(AttributeDataUtilityHelper
				.isInputRequired(modelcontext));
        box.setColumnName(AttributeDataUtilityHelper
				.getColumnName(s1, obj, modelcontext));
        box.setValue(namevalue);
        componentArray.addGUIComponent(box);
        
       
        
		///netmarkets/jsp/ext/cust/vehicle/addVehicle.jsp
		if(modelcontext.getDescriptorMode() == ComponentMode.CREATE){
			//受控PDF图纸
			if (("cn.tianma.ControlDocument").equals(typeidentifier.getTypename())) {
				//if(s.indexOf("LocationZH")!=-1){
				String u = "<a href=\"" + baseUrl + "app/#ptc1/tcomp/infoPage.jsp\" >" + "下载模板" + "</a>";
					componentArray
					.addGUIComponent(new HTMLComponent(u));
				//}
				
				localObject = componentArray;
			}else{
				localObject=componentArray;
			}
		}else{
			localObject=super.getDataValue(s, obj, modelcontext);
		}
		
		return localObject;
	}

}
